package com.alinu.workbench.web.controller;

import com.alinu.utils.PrintJson;
import com.alinu.utils.ServiceFactory;
import com.alinu.workbench.service.TranService;
import com.alinu.workbench.service.impl.TranServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author chenzuwei
 * @date 2021/3/24
 * @description
 */
public class ChartController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getServletPath();
        assert path != null;
        if ("/workbench/chart/getTransCharts.do".equals(path)) {
            getTransCharts(request, response);
        }
    }

    private void getTransCharts(HttpServletRequest request, HttpServletResponse response) {
        TranService tranService = (TranService) ServiceFactory.getService(new TranServiceImpl());

        Map<String, Object> resultMap = tranService.getTransCharts();

        PrintJson.printJsonObj(response, resultMap);

    }
}
